#include <iostream>  
#include <vector>  
using namespace std;  
  
struct TreeNode {  
    int val;  
    TreeNode* left;  
    TreeNode* right;  
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}  
};  
  
void getPath(TreeNode* root, vector<int>& path) {  
    if (root == NULL) {  
        return;  
    }  
    path.push_back(root->val);  
    if (root->left == NULL && root->right == NULL) {  
        // 叶子结点，返回路径  
        for (int i = 0; i < path.size(); i++) {  
            cout << path[i] << " ";  
        }  
        cout << endl;  
        return;  
    }  
    // 递归遍历左子树和右子树  
    getPath(root->left, path);  
    getPath(root->right, path);  
}  
  
int main() {  
    TreeNode* root = new TreeNode(1);  
    root->left = new TreeNode(2);  
    root->right = new TreeNode(3);  
    root->left->left = new TreeNode(4);  
    root->left->right = new TreeNode(5);  
    root->right->left = new TreeNode(6);  
    root->right->right = new TreeNode(7);  
  
    vector<int> path;  
    getPath(root, path);  
    return 0;  
}